﻿using System;
using System.Collections.Generic;

class Nosene
{
    static void Main()
    {
        int bag = int.Parse(Console.ReadLine());
        int rooms = int.Parse(Console.ReadLine());
        string[] treasuresStr = new string[rooms];
        string input = Console.ReadLine();
        treasuresStr = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        int counter = 0;

        for (int i = 0; i < rooms; i++)
        {
            int roomTres = int.Parse(treasuresStr[i]);

            if (bag - roomTres >= 0)
            {
                bag -= roomTres;
                counter++;
            }
            else
            {
                break;
            }
        }

        Console.WriteLine(counter);
    }
}